//
//  HEIMKit.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/27.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEIMKit.h"

@interface HEIMKit ()

@property (nonatomic, strong) NSMutableDictionary *usersDict;

@end

@implementation HEIMKit

#pragma mark - LifeCycle
+(instancetype)sharedKit {
    static dispatch_once_t onceToken;
    static HEIMKit *instance;
    dispatch_once(&onceToken, ^{
        instance = [[HEIMKit alloc] init];
    });
    return instance;
}

- (void)registeUserInfos:(NSArray <HEIMKitInfo *>*)infos {
    for (HEIMKitInfo *user in infos) {
        [self registeUserInfo: user];
    }
}

- (void)registeUserInfo:(HEIMKitInfo *)info {
    [self.usersDict setValue:info forKey: info.infoId];
}

- (void)removeUserInfoById:(NSString *)usid {
    [self.usersDict removeObjectForKey: usid];
}

- (HEIMKitInfo *)infoByUser:(NSString *)userId {
    return [self.usersDict objectForKey:userId];
}

- (void)removeAllUserInfos {
    [self.usersDict removeAllObjects];
}

- (NSMutableDictionary *)usersDict {
    if (!_usersDict) {
        _usersDict = [NSMutableDictionary dictionary];
    }
    return _usersDict;
}

@end
